package steps;

import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.Toast;


import com.metodo_ahp.usuario.aplicacionmetodoahp.R;

import java.util.ArrayList;

import adapters.ExpListAdapterCompararCriterios;
import dialog.DlgVerDetallesCriterios;
import gestores.GestorModeloAHP;
import libreria.WizardStep;

/**
 * Created by Usuario on 26/09/2014.
 */
public class step_2_comp_criterios extends WizardStep {
    ExpandableListAdapter listAdapter;
    ExpandableListView expListView;
    Button btnConsistencia;
    Button btnVerDetalles;

    GestorModeloAHP gestorModelo;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        gestorModelo = (GestorModeloAHP) getActivity().getApplicationContext();

        if(gestorModelo.getListaCriterios()!=null)
            gestorModelo.inicializarMatrizBaseCriterios();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);

        return inflater.inflate(R.layout.step_2_comparar_criterios_exp_list, container, false);
    }

    public step_2_comp_criterios() {
    }

    /**
     * Cuando la fragmente esté completamente creada.
     * @param savedInstanceState
     */
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        btnConsistencia = (Button)  this.getView().findViewById(R.id.btnConsistencia);
        btnConsistencia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean band = gestorModelo.verificarConsistencia();
                if(band == true){
                    Toast.makeText(getActivity(),R.string.consistencia_correcta,Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(getActivity(),R.string.consistencia_incorrecta,Toast.LENGTH_LONG).show();
                }
                 notifyCompleted(band);
            }
        });

        btnVerDetalles = (Button) this.getView().findViewById(R.id.btnVerDetalles);
        btnVerDetalles.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogFragment newFragment = DlgVerDetallesCriterios.newInstance(gestorModelo);
                newFragment.show(getActivity().getFragmentManager(),"tag");
            }
        });

        // get the listview
        expListView = (ExpandableListView) this.getView().findViewById(R.id.expLstCompCriterios);
        listAdapter = new ExpListAdapterCompararCriterios(this.getActivity(),gestorModelo.getListaCriterios(), gestorModelo.buildDataChildren());
        // setting list adapter

        expListView.setAdapter(listAdapter);

    }
}
